package com.gaohe.post.controller;

import java.util.List;
import java.io.IOException;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.gaohe.common.log.annotation.Log;
import com.gaohe.common.log.enums.BusinessType;
import com.gaohe.common.security.annotation.RequiresPermissions;
import com.gaohe.post.domain.FmPostOrder;
import com.gaohe.post.service.IFmPostOrderService;
import com.gaohe.common.core.web.controller.BaseController;
import com.gaohe.common.core.web.domain.AjaxResult;
import com.gaohe.common.core.utils.poi.ExcelUtil;
import com.gaohe.common.core.web.page.TableDataInfo;

/**
 * 帖子置顶订单Controller
 * 
 * @author ruoyi
 * @date 2025-06-03
 */
@RestController
@RequestMapping("/order")
public class FmPostOrderController extends BaseController
{
    @Autowired
    private IFmPostOrderService fmPostOrderService;

    /**
     * 查询帖子置顶订单列表
     */
    @RequiresPermissions("post:order:list")
    @GetMapping("/list")
    public TableDataInfo list(FmPostOrder fmPostOrder)
    {
        startPage();
        List<FmPostOrder> list = fmPostOrderService.selectFmPostOrderList(fmPostOrder);
        return getDataTable(list);
    }

    /**
     * 导出帖子置顶订单列表
     */
    @RequiresPermissions("post:order:export")
    @Log(title = "帖子置顶订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FmPostOrder fmPostOrder)
    {
        List<FmPostOrder> list = fmPostOrderService.selectFmPostOrderList(fmPostOrder);
        ExcelUtil<FmPostOrder> util = new ExcelUtil<FmPostOrder>(FmPostOrder.class);
        util.exportExcel(response, list, "帖子置顶订单数据");
    }

    /**
     * 获取帖子置顶订单详细信息
     */
    @RequiresPermissions("post:order:query")
    @GetMapping(value = "/{postOrderId}")
    public AjaxResult getInfo(@PathVariable("postOrderId") Long postOrderId)
    {
        return success(fmPostOrderService.selectFmPostOrderByPostOrderId(postOrderId));
    }

    /**
     * 新增帖子置顶订单
     */
    @RequiresPermissions("post:order:add")
    @Log(title = "帖子置顶订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FmPostOrder fmPostOrder)
    {
        return toAjax(fmPostOrderService.insertFmPostOrder(fmPostOrder));
    }

    /**
     * 修改帖子置顶订单
     */
    @RequiresPermissions("post:order:edit")
    @Log(title = "帖子置顶订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FmPostOrder fmPostOrder)
    {
        return toAjax(fmPostOrderService.updateFmPostOrder(fmPostOrder));
    }

    /**
     * 删除帖子置顶订单
     */
    @RequiresPermissions("post:order:remove")
    @Log(title = "帖子置顶订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{postOrderIds}")
    public AjaxResult remove(@PathVariable Long[] postOrderIds)
    {
        return toAjax(fmPostOrderService.deleteFmPostOrderByPostOrderIds(postOrderIds));
    }
}
